using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace PlatformShoot
{
    public class Player : MonoBehaviour
    {
        public GameObject BulletPrefab;
        private Rigidbody2D mRig;
        private float WalkSpeed = 5f;
        private float mJumpForce = 12f;
        private bool isJump = true;
        private void Start()
        {
            mRig = GetComponent<Rigidbody2D>();
        }
        private void Update()
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                isJump = true;
            }
            Shoot();
        }
        private void FixedUpdate()
        {
            if (isJump)
            {
                mRig.velocity = new Vector2(mRig.velocity.x, mJumpForce);
                isJump = false;
            }
            mRig.velocity = new Vector2(Input.GetAxisRaw("Horizontal") * WalkSpeed, mRig.velocity.y);
        }
        void Shoot()
        {
            if (Input.GetKeyDown(KeyCode.J))
            {
                
                GameObject.Instantiate(BulletPrefab, transform.position, Quaternion.identity);
            }
        }
        private void OnTriggerEnter2D(Collider2D collision)
        {
            if (collision.gameObject.CompareTag("GamePassDoor"))
            {
                SceneManager.LoadScene("GamePassScenes");
            }
        }
    }
}

